<template>
  <div class="food-list-container">
    <div class="food-list-header">
      <h2>食物列表</h2>
      <p class="count-info">共 {{ displayedFoods.length }} 种食物</p>
    </div>
    <div class="food-list">
      <div 
        v-for="food in displayedFoods" 
        :key="food.id"
        class="food-item"
        :class="{ 'selected': selectedFood && selectedFood.id === food.id }"
      >
        <span class="food-name">{{ food.name }}</span>
        <span class="food-category">{{ getCategoryName(food.category) }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'FoodList',
  props: {
    foods: {
      type: Array,
      required: true
    },
    selectedFood: {
      type: Object,
      default: null
    },
    filterCategory: {
      type: String,
      default: 'all'
    }
  },
  computed: {
    displayedFoods() {
      if (this.filterCategory === 'all') {
        return this.foods;
      }
      return this.foods.filter(food => food.category === this.filterCategory);
    }
  },
  methods: {
    getCategoryName(category) {
      const categoryMap = {
        'chinese': '中餐',
        'western': '西餐',
        'japanese': '日料',
        'korean': '韩餐',
        'fastfood': '快餐',
        'snack': '小吃',
        'dessert': '甜品',
        'drink': '饮品'
      };
      return categoryMap[category] || category;
    }
  }
}
</script>

<style scoped>
.food-list-container {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.food-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eee;
}

.food-list-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.count-info {
  margin: 0;
  font-size: 14px;
  color: #666;
}

.food-list {
  max-height: 300px;
  overflow-y: auto;
  padding-right: 8px;
}

.food-list::-webkit-scrollbar {
  width: 6px;
}

.food-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.food-list::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 3px;
}

.food-list::-webkit-scrollbar-thumb:hover {
  background: #555;
}

.food-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 4px;
  background: #f8f9fa;
  border-radius: 8px;
  transition: all 0.2s ease;
  cursor: pointer;
}

.food-item:hover {
  background: #e9ecef;
  transform: translateX(4px);
}

.food-item.selected {
  background: #409eff;
  color: white;
  transform: translateX(4px);
}

.food-name {
  font-weight: 500;
  font-size: 14px;
}

.food-category {
  font-size: 12px;
  padding: 2px 8px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 12px;
}

.food-item.selected .food-category {
  background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 768px) {
  .food-list-container {
    padding: 16px;
  }
  
  .food-list {
    max-height: 250px;
  }
  
  .food-item {
    padding: 10px 14px;
  }
}
</style>